package com.lsh.oms.core.service.tool;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.lsh.base.lang.bean.Beans.getLong;

public final class Summaries {

    public static Map<String, Long> enhance(List<Map<String, Object>> group) {
        Map<String, Long> summary = new HashMap<>();
        group.forEach($ -> summary.put(key($.get("status")), getLong($, "count")));
        summary.put("count_of_all", summary.values().stream().reduce(0L, Long::sum));
        return summary;
    }

    public static String key(Object name) {
        return ("count_of_" + name).toLowerCase();
    }
}
